﻿using System;

class Bank
{
    private string bankName;
    public string BankName
    {
        get { return bankName; }
        set { bankName = value; }
    }

    public Bank(string name)
    {
        bankName = name;
    }
}

class Account
{
    protected string accountNumber;
    protected decimal balance;

    public string AccountNumber
    {
        get { return accountNumber; }
    }
    public decimal Balance
    {
        get { return balance; }
    }

    public Account(string number, decimal initBalance)
    {
        accountNumber = number;
        balance = initBalance;
    }

    //存款
    public virtual void Deposit(decimal amount)
    {
        balance += amount;
    }

    //取款
    public virtual void Withdraw(decimal amount)
    {
        if (balance >= amount)
        {
            balance -= amount;
        }
        else
        {
            Console.WriteLine("余额不足");
        }
    }
}

class CreditAccount : Account
{
    private decimal creditLimit;

    public decimal CreditLimit
    {
        get { return creditLimit; }
    }

    public CreditAccount(string number, decimal initBalance, decimal limit) : base(number, initBalance)
    {
        creditLimit = limit;
    }

    public override void Withdraw(decimal amount)
    {
        if (Balance + creditLimit >= amount)
        {
            balance -= amount;
        }
        else
        {
            Console.WriteLine("超过信用额度");
        }
    }
}

class ATM
{
    public void ProcessTransaction(Account account, decimal amount, string operation)
    {
        if (operation == "Deposit")
        {
            account.Deposit(amount);
            Console.WriteLine($"账号 {account.AccountNumber} 存款 {amount} 成功");
        }
        else if (operation == "Withdraw")
        {
            account.Withdraw(amount);
            Console.WriteLine($"账号 {account.AccountNumber} 取款 {amount} 成功");
        }
    }
}

class Program
{
    static void Main()
    {
        // 创建银行对象并初始化名字
        Bank bank = new Bank("工商银行");
        Console.WriteLine($"当前银行：{bank.BankName}");

        // 通过BankName属性修改银行名字
        bank.BankName = "建设银行";
        Console.WriteLine($"修改后银行：{bank.BankName}");

        // 创建普通账号对象
        Account normalAccount = new Account("123456", 1000);
        Console.WriteLine($"创建普通账号：{normalAccount.AccountNumber},余额:{normalAccount.Balance}");
        // 创建信用账号对象
        CreditAccount creditAccount = new CreditAccount("654321", 500, 2000);
        Console.WriteLine($"创建信用账号：{creditAccount.AccountNumber},余额:{creditAccount.Balance},信用额度:{creditAccount.CreditLimit}");
        // 创建ATM对象
        ATM atm = new ATM();

        // 普通账号存款操作
        atm.ProcessTransaction(normalAccount, 500, "Deposit");
        Console.WriteLine($"普通账号 {normalAccount.AccountNumber}余额: {normalAccount.Balance}");

        // 普通账号取款操作
        atm.ProcessTransaction(normalAccount, 800, "Withdraw");
        Console.WriteLine($"普通账号 {normalAccount.AccountNumber} 余额: {normalAccount.Balance}");

        // 信用账号取款操作
        atm.ProcessTransaction(creditAccount, 2500, "Withdraw");
        Console.WriteLine($"信用账号 {creditAccount.AccountNumber} 余额: {creditAccount.Balance}");

        Console.ReadLine();
    }
}